﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Admin_addevent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!fuA.HasFile)
            return;
        try
        {
            string fileName = DateTime.Now.Ticks.ToString() + ".jpeg";
            string destFilePath = Server.MapPath(@"~\pictures\tmppromotion\") + fileName;

            fuA.SaveAs(destFilePath);

            imgA.ImageUrl = Page.ResolveUrl(@"~\pictures\tmppromotion\" + fileName);
            hfA.Value = fileName;
            string a = tbStartDay.Text;
        }
        catch (System.Exception ex)
        {

        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!fuB.HasFile)
            return;
        try
        {
            string fileName = DateTime.Now.Ticks.ToString() + ".jpeg";
            string destFilePath = Server.MapPath(@"~\pictures\tmppromotion\") + fileName;

            fuB.SaveAs(destFilePath);

            imgB.ImageUrl = Page.ResolveUrl(@"~\pictures\tmppromotion\" + fileName);
            hfB.Value = fileName;
        }
        catch (System.Exception ex)
        {

        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(hfA.Value) || String.IsNullOrEmpty(hfB.Value))
        {
            AlertHelper.AlertErrorMsg("nopicutre", "请上传图片");
            return;
        }

        if (String.IsNullOrEmpty(tbTitle.Text))
        {
            AlertHelper.AlertErrorMsg("errortitle", "请输入标题");
            return;
        }
        DateTime startDay = Convert.ToDateTime(tbStartDay.Text);
        DateTime dueDay = Convert.ToDateTime(tbDueDay.Text);
        if (!(startDay <= dueDay))
        {
            AlertHelper.AlertErrorMsg("errorday", "结束日期不能早于开始日期");
            return;
        }
            
        dueDay = dueDay.AddDays(1);
        Promotion promotion = new Promotion();
        promotion.PictureAName = hfA.Value;
        promotion.PictureBName = hfB.Value;
        promotion.PromotionTitle = tbTitle.Text;
        promotion.StartDay = startDay;
        promotion.DueDay = dueDay;
        PromotionService.GetInstance().AddPromotion(promotion);

        Response.Redirect(ResolveUrl("~/Admin/eventManagement.aspx"));
    }
}
